package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    // 根据时间和类型统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{time} AND TYPE = #{type}")
    Integer findByTimeAndType(@Param("time") String time, @Param("type") String type);

    // 根据时间统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{time}")
    Integer findByTime(String time);

    // 次日留存统计
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today} \n" +
            " AND user_id IN (SELECT  user_id FROM tb_log WHERE log_time=#{yesterday} AND TYPE = '0102')")
    Integer findByActive(@Param("today") String today,@Param("yesterday") String yesterday);
}